package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PopulationQianyi;
import com.ruoyi.system.service.IPopulationQianyiService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 户口迁移Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@Controller
@RequestMapping("/system/cz_qianyi")
public class PopulationQianyiController extends BaseController
{
    private String prefix = "system/cz_qianyi";

    @Autowired
    private IPopulationQianyiService populationQianyiService;

    @RequiresPermissions("system:cz_qianyi:view")
    @GetMapping()
    public String cz_qianyi()
    {
        return prefix + "/cz_qianyi";
    }

    /**
     * 查询户口迁移列表
     */
    @RequiresPermissions("system:cz_qianyi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PopulationQianyi populationQianyi)
    {
        startPage();
        List<PopulationQianyi> list = populationQianyiService.selectPopulationQianyiList(populationQianyi);
        return getDataTable(list);
    }

    /**
     * 导出户口迁移列表
     */
    @RequiresPermissions("system:cz_qianyi:export")
    @Log(title = "户口迁移", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PopulationQianyi populationQianyi)
    {
        List<PopulationQianyi> list = populationQianyiService.selectPopulationQianyiList(populationQianyi);
        ExcelUtil<PopulationQianyi> util = new ExcelUtil<PopulationQianyi>(PopulationQianyi.class);
        return util.exportExcel(list, "户口迁移数据");
    }

    /**
     * 新增户口迁移
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存户口迁移
     */
    @RequiresPermissions("system:cz_qianyi:add")
    @Log(title = "户口迁移", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PopulationQianyi populationQianyi)
    {
        return toAjax(populationQianyiService.insertPopulationQianyi(populationQianyi));
    }

    /**
     * 修改户口迁移
     */
    @RequiresPermissions("system:cz_qianyi:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PopulationQianyi populationQianyi = populationQianyiService.selectPopulationQianyiById(id);
        mmap.put("populationQianyi", populationQianyi);
        return prefix + "/edit";
    }

    /**
     * 修改保存户口迁移
     */
    @RequiresPermissions("system:cz_qianyi:edit")
    @Log(title = "户口迁移", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PopulationQianyi populationQianyi)
    {
        return toAjax(populationQianyiService.updatePopulationQianyi(populationQianyi));
    }

    /**
     * 删除户口迁移
     */
    @RequiresPermissions("system:cz_qianyi:remove")
    @Log(title = "户口迁移", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(populationQianyiService.deletePopulationQianyiByIds(ids));
    }
}
